<?php
namespace Admin\Controller;
use Gy_Library\DBCont;
use Gy_Library\GyListController;

class PracticeTypeController extends BasicOperationController{

    public function index(){

        $map = [];
        $news_model = D('PracticeType');
        $count = $news_model->getListForCount($map);
        $per_page = C('ADMIN_PER_PAGE_NUM', null, false);
        if($per_page === false){
            $page = new \Gy_Library\GyPage($count);
        }
        else{
            $page = new \Gy_Library\GyPage($count, $per_page);
        }

        $data_list = $news_model->getListForPage($map, $page->nowPage, $page->listRows, 'sort asc,id asc');

        // 设置Tab导航数据列表
        $status_list = DBCont::getStatusList();
        foreach ($status_list as $key => $val) {
            $tab_list[$key]['title'] = $val;
            $tab_list[$key]['href']  = U('index', array('status' => $key));
        }

        // 使用Builder快速建立列表页面。
        $builder = new \Qscmf\Builder\ListBuilder();

        $builder = $builder->setMetaTitle('口译练习类型管理')  // 设置页面标题
            ->addTopButton('addnew')   // 添加新增按钮;
            ->addTopButton('save', array('title' => '保存排序'))
            ->addTopButton('self', array('title' => '返回', 'href' => U('Practice/index'),'class'=>'btn btn-default'));  // 添加返回按钮;
        $builder                                        //->addTopButton('delete')   // 添加删除按钮
            ->setNIDByNode(MODULE_NAME,'Practice',__FUNCTION__)
            ->addTableColumn('title', '口译练习类型')
            ->addTableColumn('sort', '排序', '', '', true)
            ->addTableColumn('status', '状态', 'status', '', false)
            ->addTableColumn('right_button', '操作', 'btn')
            ->setTableDataList($data_list)     // 数据列表
            ->setTableDataPage($page->show())  // 数据列表分页
            ->addRightButton('edit')           // 添加编辑按钮
            ->addRightButton('forbid')         // 添加禁用/启用按钮
            ->addRightButton('delete')         // 添加删除按钮
            ->display();
    }
    public function add(){
        parent::add();
        $builder = new \Qscmf\Builder\FormBuilder();
        $info = ["status"=>1];
        $builder->setMetaTitle('新增口译练习类型'); //设置页面标题
        $this->formBuilderPublic($builder);
        $builder->setFormData($info)->display();
    }
    public function edit($id){
        parent::edit();
        $info = D($this->dbname)->getOne($id);
        $builder = new \Qscmf\Builder\FormBuilder();
        $builder->setMetaTitle('编辑口译练习类型');
        $builder->addFormItem('id', 'hidden', 'ID');
        $this->formBuilderPublic($builder);
        $builder->setFormData($info)->display();
    }
    public function formBuilderPublic(&$builder){
        $builder->setNIDByNode(MODULE_NAME,'Practice','index')
            ->addFormItem('title', 'text', '*练习类型')
            ->addFormItem('sort', 'text', '排序')
            ->addFormItem('status', 'select', '状态', '', DBCont::getStatusList());
    }

    public function getNotDeleteDataList()
    {
        /*
         * 0、表名 1、关联的列名 2、删除失败需要提示的消息
         */
        return [
            ['Practice','type_id','请清空该类型下的练习内容，再进行此操作。'],
        ];
    }
}







































